package com.example.security.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * 扩展审计字段自动填充规则
 * <p>
 * Created by devinlee in 2022.09.05
 */
// @Component
public class TableMetaObjectHandler implements MetaObjectHandler {

    private static final String DEFAULT_OPERATOR = "system";
    
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createBy", DEFAULT_OPERATOR, metaObject);
        this.setFieldValByName("createDate", new Date(), metaObject);
        this.setFieldValByName("updateBy", DEFAULT_OPERATOR, metaObject);
        this.setFieldValByName("updateDate", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateBy", DEFAULT_OPERATOR, metaObject);
        this.setFieldValByName("updateDate", new Date(), metaObject);
    }
}